package com.matrix.java.chap_04.example;

import java.util.Scanner;

public class Case4_04 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("输入16进制数: ");
        String hexadecimal = input.next();
        if (hexadecimal.length() != 1) {
            System.out.println("You must enter exactly one character");
            System.exit(1);
        }
        char ch = Character.toUpperCase(hexadecimal.charAt(0));
        if (ch <= 'F' && ch >= 'A') {
            int value = ch - 'A' + 10;
            System.out.println("The decimal value for hex digit " + ch + " is " + value);
        } else if (Character.isDigit(ch)) {
            System.out.println("The decimal value for hex digit " + ch + " is " + ch);
        } else {
            System.out.println(ch + "is an invalid input");
            input.close();
        }
    }
}
